#include "../include/route.h"

using namespace std;
namespace vectorMap
{

Route::Route(RouteMap* map):MapObject(map)
{
	lengthKnown=0;
}

Route::~Route()
{
}


}
vectorMap::Route::Route(Node* node):MapObject(node->map)
{
	nodes.push_back(node);
}

int vectorMap::Route::length()
{
	if (lengthKnown)
		return cachedLength;
	lengthKnown = true;
	cachedLength=0;
	vector<Node*>::iterator iter = nodes.begin();
	do{
		cachedLength+=(*iter)->place->length((*++iter)->place);
	}while(iter!=nodes.end());
    return cachedLength;

}

void vectorMap::Route::prepend(Node* node)
{
	nodes.insert(nodes.begin(), node);
}
void vectorMap::Route::append(Node* node)
{
	nodes.push_back(node);
}
